package com.yufubao.strat.config;


import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import com.yufubao.framework.interceptor.AppletInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 张一恒
 * @version 1.0
 * @description: 拦截路径
 * @date 2024/8/27 09:59
 */
@Component
public class GlobalWebMvnConfig implements WebMvcConfigurer {

    @Autowired
    private AppletInterceptor appletInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(appletInterceptor).addPathPatterns("/applet/**")
                .excludePathPatterns("/applet/management/**").order(0);

        // 注册 Sa-Token 拦截器，打开注解式鉴权功能
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/applet/management/**")
                .excludePathPatterns("/applet/management/manager/power/login")
                .excludePathPatterns("/applet/management/manager/power/login")
//                .excludePathPatterns("/applet/management/manager/list")
                .order(1);
    }
}
